def dfs(n,ans,path,lefts):
    if len(path)==2*n:
        ans.append(''.join(path))
        return 
    if lefts<n:
        path.append('(')
        dfs(n,ans,path,lefts+1)
        path.pop()
    if (len(path)-lefts)<n and lefts>(len(path)-lefts):
        path.append(')')
        dfs(n,ans,path,lefts)
        path.pop()

def solve(n):
    ans=[]
    dfs(n,ans,[],0)
    return ans 

print(solve(3))
print(solve(1))
